//
//  RegisteredViewController.m
//  O2O Product
//
//  Created by 特沃兹 on 2017/12/29.
//  Copyright © 2017年 Product Author. All rights reserved.
//

#import "RegisteredViewController.h"

@interface RegisteredViewController ()

@end

@implementation RegisteredViewController

#pragma mark - ---------- Lazy Loading（懒加载） ----------
-(TextFieldView *)PhoneText
{
    if (_PhoneText == nil) {
        _PhoneText = [[TextFieldView alloc]initWithFrame:CGRectMake(20, 50+TopBarHeight, Main_Screen_Width-40, 50)];
        _PhoneText.backgroundColor = [UIColor clearColor];
        _PhoneText.layer.borderWidth = 1;
        _PhoneText.layer.borderColor = [ChangeColor hexStringToColor:@"d2d2d2"].CGColor;
        [_PhoneText.leftIcon setImage:[UIImage imageNamed:@"Login_Phone"] forState:UIControlStateNormal];
        _PhoneText.placeholderString = @"请输入手机号码";
        _PhoneText.maxTextLength = 11;
        _PhoneText.layer.cornerRadius = 2;
        _PhoneText.TextF.keyboardType = UIKeyboardTypePhonePad;
    }
    return _PhoneText;
}
-(TextFieldView *)ValidationText
{
    if (_ValidationText == nil) {
        _ValidationText = [[TextFieldView alloc]initWithFrame:CGRectMake(20, 50+TopBarHeight, Main_Screen_Width-100, 50)];
        _ValidationText.backgroundColor = [UIColor clearColor];
        _ValidationText.layer.borderWidth = 1;
        _ValidationText.layer.borderColor = [ChangeColor hexStringToColor:@"d2d2d2"].CGColor;
        [_ValidationText.leftIcon setImage:[UIImage imageNamed:@"Login_Validation"] forState:UIControlStateNormal];
        _ValidationText.placeholderString = @"请输入验证码";
        _ValidationText.maxTextLength = 6;
        _ValidationText.layer.cornerRadius = 2;
        _ValidationText.TextF.keyboardType = UIKeyboardTypePhonePad;
    }
    return _ValidationText;
}
-(UIButton *)ValidationButton{
    if (_ValidationButton == nil) {
        _ValidationButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_ValidationButton setBackgroundColor:[ChangeColor hexStringToColor:@"f0f0f0"]];
        [_ValidationButton setTitle:@"验证码" forState:UIControlStateNormal];
        [_ValidationButton setTitleColor:Color_999999 forState:UIControlStateNormal];
        [_ValidationButton.layer setCornerRadius:2];
        [_ValidationButton.layer setBorderWidth:1];
        [_ValidationButton.layer setBorderColor:[ChangeColor hexStringToColor:@"d2d2d2"].CGColor];
        [_ValidationButton addTarget:self action:@selector(ValidationAction) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _ValidationButton;
}
-(TextFieldView *)SMSText
{
    if (_SMSText == nil) {
        _SMSText = [[TextFieldView alloc]initWithFrame:CGRectMake(20, 50+TopBarHeight, Main_Screen_Width-100, 50)];
        _SMSText.backgroundColor = [UIColor clearColor];
        _SMSText.layer.borderWidth = 1;
        _SMSText.layer.borderColor = [ChangeColor hexStringToColor:@"d2d2d2"].CGColor;
        [_SMSText.leftIcon setImage:[UIImage imageNamed:@"Login_Validation"] forState:UIControlStateNormal];
        _SMSText.placeholderString = @"请输入短信验证码";
        _SMSText.maxTextLength = 6;
        _SMSText.layer.cornerRadius = 2;
        _SMSText.TextF.keyboardType = UIKeyboardTypePhonePad;
    }
    return _SMSText;
}
-(UIButton *)SMSButton{
    if (_SMSButton == nil) {
        _SMSButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_SMSButton setBackgroundColor:Color_d73b3c];
        [_SMSButton setTitle:@"获取短信验证码" forState:UIControlStateNormal];
//        [_SMSButton setTitleColor:Color_999999 forState:UIControlStateNormal];
        [_SMSButton.layer setCornerRadius:2];
        [_SMSButton addTarget:self action:@selector(SMSAction) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _SMSButton;
}
-(TextFieldView *)PasswordText
{
    if (_PasswordText == nil) {
        _PasswordText = [[TextFieldView alloc]initWithFrame:CGRectMake(20, 50+TopBarHeight, Main_Screen_Width-40, 50)];
        _PasswordText.backgroundColor = [UIColor clearColor];
        _PasswordText.layer.borderWidth = 1;
        _PasswordText.layer.borderColor = [ChangeColor hexStringToColor:@"d2d2d2"].CGColor;
        [_PasswordText.leftIcon setImage:[UIImage imageNamed:@"Login_Pass"] forState:UIControlStateNormal];
        _PasswordText.placeholderString = @"请输入6-12位英文字符及数字";
        _PasswordText.maxTextLength = 12;
        _PasswordText.layer.cornerRadius = 2;
        _PasswordText.TextF.keyboardType = UIKeyboardTypePhonePad;
    }
    return _PasswordText;
}
-(UIButton *)RegisteredButton{
    if (_RegisteredButton == nil) {
        _RegisteredButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_RegisteredButton setBackgroundColor:Color_d73b3c];
        [_RegisteredButton setTitle:@"注册" forState:UIControlStateNormal];
        [_RegisteredButton setTitleColor:[ChangeColor hexStringToColor:@"fefefe"] forState:UIControlStateNormal];
        [_RegisteredButton.layer setCornerRadius:2];
        [_RegisteredButton addTarget:self action:@selector(RegisteredAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _RegisteredButton;
}
-(UIButton *)LoginButton{
    if (_LoginButton == nil) {
        _LoginButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_LoginButton setTitle:@"登录" forState:UIControlStateNormal];
        [_LoginButton setTitleColor:Color_333333 forState:UIControlStateNormal];
        [_LoginButton addTarget:self action:@selector(LoginAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _LoginButton;
}
-(UIButton *)AgreementButton{
    if (_AgreementButton == nil) {
        _AgreementButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_AgreementButton setTitle:@"同意《用户注册协议》" forState:UIControlStateNormal];
        [_AgreementButton setTitleColor:Color_999999 forState:UIControlStateNormal];
        [_AgreementButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [_AgreementButton setImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
    }
    return _AgreementButton;
}
#pragma mark - ----------   Lifecycle（生命周期） ----------
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self InitSubView];

}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}
#pragma mark - ---------- Private Methods（私有方法） ----------

#pragma mark initliaze data(初始化数据)

#pragma mark config control（布局控件）
-(void)InitSubView{
    [self.view  addSubview:self.PhoneText];
    [self.PhoneText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_offset(0);
        make.size.mas_offset(CGSizeMake(Main_Screen_Width-40, 50));
        make.top.mas_offset(TopBarHeight+50);
    }];
    [self.view addSubview:self.ValidationButton];
    [self.ValidationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.PhoneText.mas_bottom).offset(10);
        make.right.equalTo(self.PhoneText.mas_right).offset(0);
        make.size.mas_offset(CGSizeMake(194/2, 50));
    }];
    [self.view  addSubview:self.ValidationText];
    [self.ValidationText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.PhoneText.mas_bottom).offset(10);
        make.left.equalTo(self.PhoneText.mas_left).offset(0);
        make.right.equalTo(self.ValidationButton.mas_left).offset(-10);
        make.bottom.equalTo(self.ValidationButton.mas_bottom).offset(0);
    }];
    [self.view addSubview:self.SMSButton];
    [self.SMSButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.ValidationButton.mas_bottom).offset(10);
        make.right.equalTo(self.ValidationButton.mas_right).offset(0);
        make.size.mas_offset(CGSizeMake(260/2, 50));
    }];
    [self.view  addSubview:self.SMSText];
    [self.SMSText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.ValidationText.mas_bottom).offset(10);
        make.left.equalTo(self.ValidationText.mas_left).offset(0);
        make.right.equalTo(self.SMSButton.mas_left).offset(0);
        make.bottom.equalTo(self.SMSButton.mas_bottom).offset(0);
    }];
    [self.view addSubview:self.PasswordText];
    [self.PasswordText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_offset(0);
        make.top.equalTo(self.SMSText.mas_bottom).offset(10);
        make.size.mas_offset(CGSizeMake(Main_Screen_Width-40, 50));
    }];
    [self.view addSubview:self.RegisteredButton];
    [self.RegisteredButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_offset(0);
        make.top.equalTo(self.PasswordText.mas_bottom).offset(50);
        make.size.mas_offset(CGSizeMake(Main_Screen_Width-40, 50));
    }];
    [self.view addSubview:self.LoginButton];
    [self.LoginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.PhoneText.mas_right).offset(0);
        make.bottom.equalTo(self.PhoneText.mas_top).offset(-10);
        make.size.mas_offset(CGSizeMake(40, 40));
    }];
    [self.view addSubview:self.AgreementButton];
    [self.AgreementButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.RegisteredButton.mas_bottom).offset(10);
        make.left.equalTo(self.RegisteredButton.mas_left).offset(0);
        //        make.size.mas_offset(CGSizeMake(230, 40));
    }];
    //密码提示
    _passwordLabel = [[UILabel alloc]init];
    _passwordLabel.text = @"密码由6-12位字母.数字或半角符号组成，不能是10为以下纯数字";
    _passwordLabel.numberOfLines = 0;
    _passwordLabel.textColor = Color_999999;
    [self.view addSubview:_passwordLabel];
    [_passwordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.PasswordText.mas_bottom).offset(0);
        make.centerX.mas_offset(0);
        make.size.mas_offset(CGSizeMake(Main_Screen_Width-40, 45));
    }];
}
#pragma mark networkRequest (网络请求)



#pragma mark IBActions （点击事件xib）
-(void)ReturnViewAction{
    /*返回上一页*/
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)LoginAction{
    /*进入登录页*/
    UIViewController *vc = self.presentingViewController;
    while (vc.presentingViewController) {
        vc = vc.presentingViewController;
    }
    [vc dismissViewControllerAnimated:YES completion:NULL];
}
//验证码
-(void)ValidationAction{
    /*1.验证码图片点击刷新；
     2.验证码有效期5分钟*/
}
//短信
-(void)SMSAction{
    /*
     1.只允许输入数字；
     2.点击先校验手机号是否为空，错误飘字“请输入手机号”；
     3.手机号格式错误飘字“请输入正确的手机号”；
     4.判断手机号是否注册过，注册过则飘字“该号码已注册”；
     5.判断图形验证码是否为空，错误飘字“请输入图形验证码”；
     6.判断图形验证码是否正确，错误飘字“请输入正确的图形验证码”；
     7.手机号无误后发送6位数验证码，按钮文本变为60S倒计时，不可点击；
     */
    
}
-(void)PasswordClearAction{
    /*可以明文查看已输入的密码*/
}
//用户注册协议
-(void)agreementAction{
    /*
     1.默认勾选，点击《 用户注册协议》进入用户注册协议页；
     2.不勾选则注册按钮变灰，点击按钮飘字“同意《 用户注册协议》方可注册帐号”
     */
    [self presentViewController:[AgreementViewController new] animated:YES completion:nil];

}
//注册用户
-(void)RegisteredAction{
    /*
     手机号、验证码、密码为空、协议未勾选的时候呈灰态；
     1.点击后首先验证手机是否为空，错误飘字“请输入手机号”；
     2.其次手机号已输入但未获取短信则点击本按钮则飘字“请获取验证码”；
     3.接下来校验验证码，错误飘字“验证码错误，还有N次机会”，默认3次机会。超过3次则飘字“请重新获取验证码”，获取验证码按钮变为可点击；
     3.接下来校验密码，要求请看密码框下方文字，错误飘字提示具体触犯了哪个规则；
     
     3.在2分钟内输入正确的验证码即可注册，跳转至来源页。
     
     4.若是第三方绑定注册则按钮文本改为“注册并绑定”
     */
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
